<template>
  <a-modal
    title="详情"
    style="top: 20px;"
    width="210mm"
    v-model="visible"
    :maskClosable="false">
    <div id="printMe" class="detail">
      <div class="title">内蒙古农业大学职业技术学院家庭经济困难学生认定申请表</div>
      <div class="fb_title">院（系）<div>{{ info.deptName }}</div>年级<div>{{ info.grade }}级</div>班级<div>{{ info.classesName }}</div>学号<div>{{ info.studentNum }}</div></div>
      <table>
        <tr>
          <td style="width: 20pt;" rowspan="7">学生基本情况</td>
          <td>姓名</td>
          <td style="width: 100pt;">{{ info.studentName }}</td>
          <td style="width: 35pt;">性别</td>
          <td style="width: 30pt;">{{ info.gender | genderFilter }}</td>
          <td style="width: 35pt;">民族</td>
          <td style="width: 90pt;">{{ info.studentNation | studentNationFilter }}</td>
          <td style="width: 52pt;">出生年月</td>
          <td>{{ info.birthday }}</td>
        </tr>
        <tr>
          <td style="width: 35pt;">身份证号</td>
          <td colspan="3">{{ info.idCard }}</td>
          <td style="width: 10pt;" colspan="2">户籍（转入学校户籍学生填写入学前户籍）</td>
          <td colspan="2">{{ info.householdRegisterType | householdRegisterTypeFilter }}</td>
        </tr>
        <tr>
          <td rowspan="5">家庭情况</td>
          <td>家庭人口数</td>
          <td colspan="2">{{ info.population }}</td>
          <td colspan="2">家庭在学成员人数</td>
          <td colspan="2">{{ info.studyPopulation }}</td>
        </tr>
        <tr>
          <td style="border-right: none;">家庭人均收入</td>
          <td style="border: none;">{{ info.perCapitaIncome }}</td>
          <td style="border-left:none ;text-align: left;" colspan="5">（元）</td>
        </tr>
        <tr>
          <td style="text-align: left;" rowspan="1" colspan="7">
            <template v-if="item.dictSort<=3" v-for="item in stPoorSituationList">{{ item.dictSort+'.'+ item.dictLabel+(parseInt(item.dictValue)&info.situation?' ☑是□否 ':' □是☑否 ') }}</template>
          </td>
        </tr>
        <tr><td style="text-align: left;" rowspan="1" colspan="7">
          <template v-if="item.dictSort>3 && item.dictSort<8 " v-for="item in stPoorSituationList">{{ item.dictSort+'.'+ item.dictLabel+(parseInt(item.dictValue)&info.situation?' ☑是□否 ':' □是☑否 ') }}</template>
        </td></tr>
        <tr><td style="text-align: left;" rowspan="1" colspan="7">
          <template v-if="item.dictSort>=8" v-for="item in stPoorSituationList">{{ item.dictSort+'.'+ item.dictLabel+(parseInt(item.dictValue)&info.situation?' ☑是□否 ':' □是☑否 ') }}</template>
        </td></tr>
        <tr>
          <td rowspan="2">家庭通讯信息</td>
          <td>户籍地址</td>
          <td colspan="7">{{ info.householdRegisterAddress +'  '+info.householdRegisterStreet }}</td>
        </tr>
        <tr>
          <td>邮政编码</td>
          <td>{{ info.postcode }}</td>
          <td colspan="2">联系人</td>
          <td colspan="2">{{ info.liaisonMan }}</td>
          <td>联系电话</td>
          <td>{{ info.liaisonManPhone }}</td>
        </tr>
        <tr>
          <td style="writing-mode: sideways-rl;">家庭成员情况（直系亲属）</td>
          <td colspan="8" style="padding: 0;border: none;">
            <table style="margin: 0;border: none; width: 100%;">
              <tr>
                <td style="border-top: none;border-left:none;">姓名</td>
                <td style="border-top: none;">与学生<br>关系</td>
                <td style="border-top: none;">年龄</td>
                <td style="border-top: none;">工作（学习）<br>单位</td>
                <td style="border-top: none;">联系电话</td>
                <td style="border-top: none;">从业<br>情况</td>
                <td style="border-top: none;">文化<br>程度</td>
                <td style="border-top: none;">年收入<br>（元）</td>
                <td style="border-top: none;border-right: none;">健康<br>状况</td>
              </tr>
              <template v-if="familyList.length>0">
                <tr v-for="(item,index) in familyList" :key="index" style="height: 20px;">
                  <td style="border-left: none;">{{ item.name }}</td>
                  <td>{{ item.relationship }}</td>
                  <td>{{ item.age }}</td>
                  <td>{{ item.unit }}</td>
                  <td>{{ item.phone }}</td>
                  <td>{{ item.background }}</td>
                  <td>{{ item.educationLevel }}</td>
                  <td>{{ item.annualIncome }}</td>
                  <td style="border-right: none;">{{ item.healthy }}</td>
                </tr>
              </template>

              <template v-if="familyList.length<4">
                <tr v-for="item in new Array(4-familyList.length)" :key="item"style="height: 20px;">
                  <td style="border-bottom: none;border-left: none;">-</td>
                  <td style="border-bottom: none;">-</td>
                  <td style="border-bottom: none;">-</td>
                  <td style="border-bottom: none;">-</td>
                  <td style="border-bottom: none;">-</td>
                  <td style="border-bottom: none;">-</td>
                  <td style="border-bottom: none;">-</td>
                  <td style="border-bottom: none;">-</td>
                  <td style="border-bottom: none;border-right: none;">-</td>
                </tr>
              </template>

            </table>
          </td>
        </tr>
        <tr>
          <td>个<br />人<br />承<br />诺</td>
          <td style="text-align: left;" colspan="5">本人保证所填信息真实，并同意授权有关部门通过信息核对系统，对所填信息进行查询、核对。<br />
            手写签名：<br/><br/>
            <pre class="date">年   月   日</pre>
          </td>
          <td style="text-align: left;" colspan="3">本人是 	同学的（囗父亲 囗母亲 囗监护人），该同学所填信息真实，同意授权有关部门通过信息核对系统，对所填信息进行查询、核对。<br />学生家长或监护人手写签名：<br />
            <pre class="date">年   月   日</pre></td>
        </tr>
        <tr >
          <td>认<br />定<br />结<br />果</td>
          <td style="text-align: left;" colspan="3">
            学生就读学校年级（专业或班级）认定评议小组意见：
            <br />
            同意该同学申请并认定等级为：<br />
            特别困难囗是囗否<br />
            一般困难囗是囗否<br />
            签字：
          </td>
          <td style="text-align: left;" colspan="3">
            学生就读学校院（系）认定工作组意见：<br />
            <br />
            签字：<br />
            <pre class="date">年   月   日</pre>
          </td>
          <td style="text-align: left;" colspan="2">
            学生就读学校认定领导小组意见：<br /><br /><br />

            签字：<br />

            <pre class="date">年   月   日</pre>

          </td>
        </tr>
      </table>
      <div style="justify-content: left; width: 180mm;">备注：此表适用于普通本、专科生。</div>
    </div>
    <a-card title="附件列表(点击下载)" :bordered="false">
      <a-empty v-if="fileList.length === 0" />
      <template v-else >
        <a-button v-for="(item,index) in fileList" :key="index" @click="download(item)" type="link">
          {{ item.name }}
        </a-button>
      </template>
    </a-card>
    <template slot="footer">

      <a-button v-print="'#printMe'" key="submit" type="primary" >
        打印
      </a-button>
      <a-button key="submit" @click="visible=false">
        关闭
      </a-button>
    </template>
  </a-modal>
</template>
<script>
import { getStudentPoorByBusiness } from '@/api/activiti'
import { getStStudentFamilyList } from '@/api/studentFamily'
import { getDictArray } from '@/utils/dict'
import { getDistFull } from '@/api/system'
import { getFileListByIds, downLoadFileById } from '@/api/dfs'
import { resolveBlobBt } from '@/utils/download'
const genderMap = {}
const householdRegisterTypeMap = {}
const studentNationMap = {}

export default {
  name: 'PoorDetail',
  components: {},
  data () {
    return {
      visible: false,
      confirmLoading: false,
      info: {},
      familyList: [],
      stPoorSituationList: [],
      formData: {},
      fileList: []
    }
  },
  props: {
    audit: {
      type: Boolean,
      default: true
    }
  },
  beforeCreate () {},
  filters: {
    genderFilter (key) {
      return genderMap[key]
    },
    householdRegisterTypeFilter (key) {
      return householdRegisterTypeMap[key]
    },
    studentNationFilter (key) {
      return studentNationMap[key]
    }
  },
  created () {
    getDictArray('sys_user_sex').then(res => {
      res.map(item => {
        genderMap[item.dictValue] = item.dictLabel
      })
    })
    getDictArray('st_poor_situation').then(res => {
      this.stPoorSituationList = res
    })
    getDictArray('household_register_type').then(res => {
      res.map(item => {
        householdRegisterTypeMap[item.dictValue] = item.dictLabel
      })
    })
    getDictArray('st_nation').then(res => {
      res.map(item => {
        studentNationMap[item.dictValue] = item.dictLabel
      })
    })
  },
  methods: {
    download (file) {
      downLoadFileById(file.id).then(res => {
        resolveBlobBt(res)
      })
    },
    show (record) {
      if (this.audit) {
        this.formData = Object.assign({
          taskId: record.id,
          procInstId: record.procInstId,
          procName: record.processDefName,
          businessKey: record.businessKey || record.id,
          procDefKey: record.processDefKey,
          applyer: record.applyer
        })
      }
      getStudentPoorByBusiness(record.businessKey || record.id).then(res => {
        if (res.code === 0) {
          this.info = res.data
          if (res.data.householdRegisterAddress) {
            getDistFull(res.data.householdRegisterAddress).then(dist => {
              if (dist.code === 0) {
                this.info.householdRegisterAddress = dist.data
              }
            })
          }

          if (res.data.file) {
            getFileListByIds(res.data.file).then(fres => {
              if (fres.code === 0) {
                this.fileList = fres.data
              }
            })
          }
          this.visible = true
        }

        return getStStudentFamilyList({ studentId: res.studentId })
      }).then(res => {
        if (res.code === 0) {
          this.familyList = res.list
        }
      })
    }
  }
}
</script>
<style lang="less">
  .detail{
    margin-top: 20px;
    color: black;
    font-family: simhei;
    font-size: 10pt;
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    // width: 180mm;

    table{
      // width: 170mm;
      margin-top: 15px;
      border: 1pt solid black;
      td{
        border: 1pt solid black;
        padding: 5pt;
        text-align: center;
      }
    }
    .date{
      margin-top: 20px;
      text-align: right;
      font-family: simhei;
      font-size: 10pt;
      margin-bottom: 0;
    }

    .title{
      font-size: 16pt;
      font-weight: 700;
    }
    .fb_title{
      display:flex;
      align-items:flex-end;
      margin-top: 10pt;
      >div{
        display: inline-block;
        height: 15pt;
        border-bottom: 1px solid black;
        vertical-align: bottom;
        text-align: center;
        padding: 0 5pt;
      }
    }
  }
</style>
